package com.ssm.sfzy.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.sfzy.entity.ConsultProblem;
import com.ssm.sfzy.mapper.ConsultProblemMapper;
import com.ssm.sfzy.service.ConsultProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @Author yang "每天都要学习呀"
 * @Date 2024 03 30 17 18
 **/
@Service
public class ConsultProblemImpl implements ConsultProblemService {
    @Autowired
    private ConsultProblemMapper consultProblemMapper;
    @Override
    public void add(ConsultProblem entity) {
        consultProblemMapper.insert(entity);

    }

    @Override
    public void edit(ConsultProblem entity) {
        consultProblemMapper.update(entity);

    }

    @Override
    public void remove(Integer id) {
        consultProblemMapper.delete(id);

    }

    @Override
    public void removeBatch(Integer[] ids) {
        consultProblemMapper.deleteBatch(ids);

    }

    @Override
    public List<ConsultProblem> find(ConsultProblem entity) {
        return consultProblemMapper.select(entity);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, ConsultProblem entity) {
        //
        PageHelper.startPage(pageNum,pageSize);
        List<ConsultProblem> list = consultProblemMapper.select(entity);
        //
        PageInfo<ConsultProblem> pageInfo = new PageInfo<>(list);
        // 整合处理
        Map<String,Object> map = new HashMap<>();
        map.put("list",pageInfo.getList());
        map.put("total",pageInfo.getTotal());
        return map;
    }

    @Override
    public ConsultProblem findById(Integer id) {
        ConsultProblem courseProblem= consultProblemMapper.selectById(id);
        return courseProblem;
    }


    @Override
    public List<ConsultProblem> getByTeacherId(Integer id) {
        return consultProblemMapper.getByTeacherId(id);
    }
}
